package com.kinghood.productcenter.controller.base;

import com.kinghood.infrastructure.api.authority.SysLogModuleEnum;
import com.kinghood.infrastructure.aspect.OperatorLog;
import com.kinghood.infrastructure.model.KingHoodResponseVO;
import com.kinghood.infrastructure.model.dto.SortReqDTO;
import com.kinghood.infrastructure.model.dto.StatusReqDTO;
import com.kinghood.productcenter.common.model.dto.base.BrandReqDTO;
import com.kinghood.productcenter.common.model.dto.base.ListBrandQueryDTO;
import com.kinghood.productcenter.service.base.IBaseBrandService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <p>
 * 基础选项-品牌 前端控制器
 * </p>
 *
 * @author KingHood
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/baseBrand")
public class BaseBrandController {
    @Resource
    private IBaseBrandService brandService;

    /**
     * 列表
     *
     * @author jp
     * @date 2023/12/20
     */
    @PostMapping("/listBrand")
    public KingHoodResponseVO listBrand(@RequestBody ListBrandQueryDTO param) {
        return KingHoodResponseVO.success(brandService.listBrand(param));
    }

    /**
     * 获取所有品牌
     *
     * @author jp
     * @date 2024/01/02
     */
    @PostMapping("/getAllBrand")
    public KingHoodResponseVO getAllBrand() {
        return KingHoodResponseVO.success(brandService.getAllBrand());
    }


    /**
     * 新增更新
     *
     * @param dirReq
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_BRAND,content = "品牌管理-新增、修改品牌")
    @PostMapping(value = "/addOrUpdateBrand")
    public KingHoodResponseVO addOrUpdateBrand(@Valid @RequestBody BrandReqDTO dirReq){
        brandService.addorUpdateBrand(dirReq);
        return KingHoodResponseVO.success();
    }


    /**
     * 根据id删除
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_BRAND,content = "品牌管理-删除品牌")
    @RequestMapping(value = "/delBrand/{id}")
    public KingHoodResponseVO delBrand(@PathVariable("id") Long id){
        brandService.delBrandById(id);
        return KingHoodResponseVO.success();
    }


    /**
     * 根据ID查询详情
     *
     * @param id id
     * @author jp
     * @date 2023/12/21
     */
    @GetMapping(value = "/detailBrand/{id}")
    public KingHoodResponseVO detailBrand(@PathVariable("id") Long id){
        return KingHoodResponseVO.success(brandService.detailBrand(id));
    }

    /**
     * 更新品牌状态
     *
     * @param param 参数
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_BRAND,content = "品牌管理-修改状态")
    @PostMapping(value = "/updateBrandStatus")
    public KingHoodResponseVO updateBrandStatus(@Valid @RequestBody StatusReqDTO param){
        brandService.updateBrandStatus(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 更新品牌排序
     *
     * @param param 参数
     * @author jp
     * @date 2023/12/21
     */
    @OperatorLog(module = SysLogModuleEnum.Type.PRODUCT_BRAND,content = "品牌管理-修改排序")
    @PostMapping(value = "/updateBrandSort")
    public KingHoodResponseVO updateBrandSort(@Valid @RequestBody SortReqDTO param){
        brandService.updateBrandSort(param);
        return KingHoodResponseVO.success();
    }

    /**
     * 下载品牌
     *
     * @param param 参数
     * @author jp
     * @date 2024/01/04
     */
    @PostMapping("/downloadBrand")
    public void downloadBrand(@RequestBody ListBrandQueryDTO param, HttpServletResponse response) {
        brandService.downloadBrand(param, response);
    }
}
